<%@ page contentType="text/html" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>

<c:set var="inspectedMessages" value="${model.accountInfo.inspectedMessageCount}"/>
<c:set var="totalMessages" value="${model.accountInfo.totalMessageCount}"/>
<c:set var="unreadMessageCount" value="${model.accountInfo.unreadMessageCount}"/>
<c:set var="unreadMessages" value="${model.accountInfo.unreadMessages}"/>

<%-- Hard-coded vars can be used for testing purposes. Just uncomment the set of vars below --%>
<%--
<c:set var="inspectedMessages" value="${10}"/>
<c:set var="totalMessages" value="${0}"/>
<c:set var="unreadMessageCount" value="${0}"/>
<c:set var="unreadMessages" value="${0}"/>
--%>
<c:set var="totalUninspectedMessages" value="${totalMessages - inspectedMessages}"/>

<style>
.email-inbox-link {
    font-weight: normal;
}
.email-inbox-link-unread {
    font-weight: bold;
}
.email-portlet-table {
width: 99%;
border-collapse: collapse;
table-layout:fixed;
}
.email-portlet-table th, .email-portlet-table td {
border: 1px solid #CCC;
}
.email-portlet-table td div, .email-portlet-table td div a {
white-space: nowrap;
overflow: hidden;
}
</style>

<div class="portlet-font">
<p>
    <c:choose>
        <c:when test="${empty model.inboxUrl}">
        Inbox(<c:out value="${unreadMessageCount}"/>)
        </c:when>
        <c:otherwise>
        <a href="<c:out value="${model.inboxUrl}" escapeXml="false"/>" target="_blank">Inbox(<c:out value="${unreadMessageCount}"/>)</a>
        </c:otherwise>
    </c:choose>
    | <a href="<portlet:renderURL><portlet:param name="action" value="preview"/></portlet:renderURL>">Refresh</a>
</p>
<c:choose>
    <c:when test="${unreadMessageCount ge 1}">
        <table cellpadding="3" cellspacing="0" class="email-portlet-table portlet-font">
        	<tr>
        		<th class="portlet-section-header">Subject</th>
        		<th class="portlet-section-header">Sender</th>
        		<th class="portlet-section-header">Date Sent</th>
        	</tr>
        	<c:forEach items="${unreadMessages}" var="message" varStatus="status">
        	<tr<c:if test="${status.count % 2 eq 0}"> class="portlet-section-alternate"</c:if>>
                <c:choose>
                    <c:when test="${empty model.inboxUrl}">
                        <td><div><c:out value="${message.subject}"/></div></td>
                    </c:when>
                    <c:otherwise>
                        <td><div><a href="<c:out value="${model.inboxUrl}" escapeXml="false"/>" target="_blank"><c:out value="${message.subject}"/></a></div></td>
                    </c:otherwise>
                </c:choose>
        		<td><div><c:out value="${message.sender}" escapeXml="true"/></div></td>
        		<td><div><fmt:formatDate value="${message.sentDate}" pattern="MM/dd/yy hh:mm a"/></div></td>
        	</tr>
        	</c:forEach>
        </table>
    </c:when>
    <c:otherwise>
        <div>
            <p class="portlet-msg-info">You have <strong>no unread email messages</strong> in your inbox at this time. <c:if test="${!empty model.inboxUrl}"><a href="<c:out value="${model.inboxUrl}" escapeXml="false"/>" target="_blank">Go To Your Inbox</a></p></c:if>
        </div>
    </c:otherwise>
</c:choose>
<c:if test="${inspectedMessages lt totalMessages}">
    <c:choose>
        <c:when test="${inspectedMessages eq 0}">
            <p class="portlet-msg-alert">No messages from your inbox were scanned. Please contact the administrator to configure this portlet properly.</p>
        </c:when>
        <c:when test="${inspectedMessages eq 1}">
            <p class="portlet-msg-alert">You have <c:out value="${totalMessages}"/> message<c:if test="${totalMessages ge 2}">s</c:if> in your inbox.  Only the first message in your inbox was scanned.  You may have unread messages within the remaining <c:out value="${totalUninspectedMessages}"/> unscanned message<c:if test="${totalUninspectedMessages ge 2}">s</c:if>.</p>
        </c:when>
        <c:otherwise>
            <p class="portlet-msg-alert">You have <c:out value="${totalMessages}"/> messages in your inbox.  Only the first <c:out value="${inspectedMessages}"/> messages in your inbox were scanned.  You may have unread messages within the remaining <c:out value="${totalUninspectedMessages}"/> unscanned message<c:if test="${totalUninspectedMessages ge 2}">s</c:if>.</p>
        </c:otherwise>
    </c:choose>
</c:if>
</div>